package main

import "fmt"

func main() {

	slice001 := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
	fmt.Println(slice001)

	mySlice002 := make([]int, 1, 6)
	fmt.Println(mySlice002)
	fmt.Println(len(mySlice002), cap(mySlice002))
	mySlice002 = append(mySlice002, 6, 7, 7, 8, 9, 10, 11, 23, 456, 77, 44, 33, 11, 19)
	fmt.Println(mySlice002)
	fmt.Println(len(mySlice002), cap(mySlice002))

	// 初始切片
	s := make([]int, 0, 2) // 长度0，容量2
	fmt.Printf("初始: len=%d cap=%d\n", len(s), cap(s))

	// 添加元素，观察容量变化
	for i := 0; i < 20; i++ {
		s = append(s, i)
		fmt.Printf("添加 %d: len=%d cap=%d\n", i, len(s), cap(s))
	}

}
